package com.minimalist.lindi.mapper;

import com.minimalist.common.entity.lindi.po.LindiTradeApplicationTemplateConfirmLetter;
import com.minimalist.common.entity.lindi.vo.tradeapplicationtemplateconfirmletter.LindiTradeApplicationTemplateConfirmLetterQueryVO;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 林地指标交易平台_交易申请确认函模板文件 映射层。
 *
 * @author 11987
 * @since 2025-06-06
 */
@Mapper
public interface LindiTradeApplicationTemplateConfirmLetterMapper extends BaseMapper<LindiTradeApplicationTemplateConfirmLetter>{

    /**
     * 根据交易申请确认函模板ID查询交易申请确认函模板
     *
     * @param tradeApplicationTemplateConfirmLetterId 交易申请确认函模板ID
     * @return 交易申请确认函模板
     */
    default LindiTradeApplicationTemplateConfirmLetter
    selectTradeApplicationTemplateConfirmLetterByTradeApplicationTemplateConfirmLetterId(
            Long tradeApplicationTemplateConfirmLetterId){
        return selectOneByQuery(QueryWrapper.create()
                .eq(LindiTradeApplicationTemplateConfirmLetter::getTemplateConfirmLetterId
                        , tradeApplicationTemplateConfirmLetterId));
    }

    /**
     * 分页查询交易申请确认函模板列表
     *
     * @param queryVO 查询条件
     * @return 分页结果
     */
    default Page<LindiTradeApplicationTemplateConfirmLetter> selectPageTradeApplicationTemplateConfirmLetterList(LindiTradeApplicationTemplateConfirmLetterQueryVO queryVO){
        QueryWrapper queryWrapper = QueryWrapper.create();
        if (queryVO.getTradeApplicationId() != null){
            queryWrapper.eq(LindiTradeApplicationTemplateConfirmLetter::getTradeApplicationId, queryVO.getTradeApplicationId());
        }
        if (queryVO.getTemplateConfirmLetterId() != null){
            queryWrapper.eq(LindiTradeApplicationTemplateConfirmLetter::getTemplateConfirmLetterId, queryVO.getTemplateConfirmLetterId());
        }
        if (queryVO.getConfirmLetterType() != null){
            queryWrapper.eq(LindiTradeApplicationTemplateConfirmLetter::getConfirmLetterType, queryVO.getConfirmLetterType());
        }
        if (queryVO.getFileId() != null){
            queryWrapper.eq(LindiTradeApplicationTemplateConfirmLetter::getFileId, queryVO.getFileId());
        }
        return paginate(queryVO.getPageNum(), queryVO.getPageSize(), queryWrapper);
    }

    /**
     * 根据交易申请ID查询交易申请确认函模板列表
     *
     * @param tradeApplicationId 交易申请ID
     * @return 交易申请确认函模板列表
     */
    default List<LindiTradeApplicationTemplateConfirmLetter> selectTradeApplicationTemplateConfirmLetterByTradeApplicationId(Long tradeApplicationId){
        return selectListByQuery(QueryWrapper.create()
                .eq(LindiTradeApplicationTemplateConfirmLetter::getTradeApplicationId
                        , tradeApplicationId));
    }
}
